package com.terrynoya.fight.stateMachine
{
	import com.terrynoya.fight.emuns.MoveType;
	import com.terrynoya.fight.emuns.PhysicsEnum;
	import com.terrynoya.fight.emuns.StateTypeEnum;
	import com.terrynoya.fight.io.TextSection;
	import com.terrynoya.geom.MVector2D;

	public class State implements IState
	{
		private var _id:int;
		
		private var _type:int;
		
		private var _physics:int;
		
		private var _moveType:int;
		
		private var _animateId:int;
		
		private var _animateIdSetted:Boolean;
		
		private var _controllers:Array;
		
		private var _playerControl:int;
		private var _playerCtrlSetted:Boolean;
		
		private var _velSet:MVector2D;
		private var _isVelSetted:Boolean;
		
		private var _hitCountPersist:Boolean;
		private var _hitdefPersistance:Boolean;
		private var _moveHitPersistance:Boolean;
		
		public function State(id:int)
		{
			this._id = id;
			this._controllers = new Array();
		}
		
		public function get moveHitPersistance():Boolean
		{
			return _moveHitPersistance;
		}

		public function set moveHitPersistance(value:Boolean):void
		{
			_moveHitPersistance = value;
		}

		public function get hitdefPersistance():Boolean
		{
			return _hitdefPersistance;
		}

		public function set hitdefPersistance(value:Boolean):void
		{
			_hitdefPersistance = value;
		}

		public function get hitCountPersist():Boolean
		{
			return _hitCountPersist;
		}

		public function set hitCountPersist(value:Boolean):void
		{
			_hitCountPersist = value;
		}

		public function get isVelSetted():Boolean
		{
			return _isVelSetted;
		}

		public function get velSet():MVector2D
		{
			return _velSet;
		}

		public function set velSet(value:MVector2D):void
		{
			_velSet = value;
			this._isVelSetted = true;
		}

		public function get playerCtrlSetted():Boolean
		{
			return _playerCtrlSetted;
		}

		public function get playerControl():int
		{
			return _playerControl;
		}

		public function set playerControl(value:int):void
		{
			_playerControl = value;
			this._playerCtrlSetted = true;
		}

		public function set controllers(value:Array):void
		{
			_controllers = value;
		}

		public function build(textSection:TextSection):void
		{
			this.initType(textSection);
			this.initPhysics(textSection);
			this.initAnim(textSection);
		}
		
		private function initMoveType(section:TextSection):void
		{
			var str:String = section.getValue("MoveType");
			if(str == null)
			{
				return;
			}
			switch(str)
			{
				case "A":
				{
					this._moveType = MoveType.Attack;
					break;
				}
				case "I":
				{
					this._moveType = MoveType.Idle;
					break;
				}
				case "H":
				{
					this._moveType = MoveType.BeingHit;
					break;
				}
			}
		}
		
		private function initAnim(section:TextSection):void
		{
			var str:String = section.getValue("anim");
			if(str == null)
			{
				return;
			}
			this.animateId = int(str);
		}
		
		private function initType(textSection:TextSection):void
		{
			var val:String = textSection.getValue("type");
			switch(val)
			{
				case "S":
				{
					this._type = StateTypeEnum.Standing;
					break;
				}
				case "A":
				{
					this._type = StateTypeEnum.Airborne;
					break;
				}
				case "C":
				{
					this._type = StateTypeEnum.Crouching;
					break;
				}
				case "U":
				{
					this._type = StateTypeEnum.Unchanged;
					break;
				}
			}
		}
		
		private function initPhysics(textSection:TextSection):void
		{
			var val:String = textSection.getValue("physics");
			switch(val)
			{
				case "S":
				{
					this._physics = PhysicsEnum.Standing;
					break;
				}
				case "A":
				{
					this._physics = PhysicsEnum.Airborne;
					break;
				}
				case "C":
				{
					this._physics = PhysicsEnum.Crouching;
					break;
				}
			}
		}
		
		public function get moveType():int
		{
			return _moveType;
		}

		public function set moveType(value:int):void
		{
			_moveType = value;
		}

		public function get animateIdSetted():Boolean
		{
			return _animateIdSetted;
		}

		public function get animateId():int
		{
			return _animateId;
		}

		public function set animateId(value:int):void
		{
			_animateId = value;
			this._animateIdSetted = true;
		}

		public function get physics():int
		{
			return _physics;
		}

		public function set physics(value:int):void
		{
			_physics = value;
		}

		public function get type():int
		{
			return _type;
		}

		public function set type(value:int):void
		{
			_type = value;
		}

		public function addController(value:StateController):void
		{
			this._controllers.push(value);
		}

		public function get id():int
		{
			return _id;
		}

		public function get controllers():Array
		{
			return _controllers;
		}
		
		public function toString():String
		{
			return "StateDef " + this._id;
		}
	}
}